package cn.zl.config;

import cn.hutool.core.util.StrUtil;
import cn.zl.common.ZLConst;
import cn.zl.common.properties.ZLProperties;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Configuration
public class ZLConfig {

    @Resource
    private ZLProperties properties;

    public String getContextPath() {
        return properties.getContextPath();
    }

    public String getIp() {
        return properties.getIp();
    }

    public String getFfmpeg() {
        return properties.getFfmpeg();
    }

    public ZLProperties.ZLM getZLM() {
        return this.properties.getZlm();
    }

    public ZLProperties.SIP getSIP() {
        return this.properties.getSip();
    }

    public String getZLMIp() {
        String ip = properties.getZlm().getIp();
        if (StrUtil.isBlank(ip)) {
            return properties.getIp();
        }
        return ip;
    }

    public int getZLMPort(String key) {
        if (ZLConst.PLAY_URL_SCHEME.RTSP.equals(key)) {
            return properties.getZlm().getRtspPort();
        }
        if (ZLConst.PLAY_URL_SCHEME.RTMP.equals(key)) {
            return properties.getZlm().getRtmpPort();
        }
        if (ZLConst.PLAY_URL_SCHEME.HTTP_FLV.equals(key)) {
            return properties.getZlm().getHttpPort();
        }
        return 0;
    }

    public Map<String, String> getPlayUrlTemplate() {
        return this.properties.getPlayUrlTemplate();
    }

    public String getSIPId() {
        return properties.getSip().getId();
    }

    public String getSIPDomain() {
        return properties.getSip().getDomain();
    }

    public String getSIPIP() {
        String sipIp = properties.getSip().getIp();
        if (StrUtil.isBlank(sipIp)) {
            String ip = properties.getIp();
            if (ip.contains(",")) {
                String[] ips = ip.split(",");
                return ips[0];
            }
            return ip;
        }
        return sipIp;
    }

    public int getSIPPort() {
        return properties.getSip().getPort();
    }

    public String getSIPPassword() {
        return properties.getSip().getPassword();
    }

    public boolean isSIPAlarm() {
        return properties.getSip().isAlarm();
    }

}
